import { Link, useLocalSearchParams } from 'expo-router'; import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextInput, View, } from 'react-native'; import { useOffice } from '@/features/offices/hooks/useOffice'; import { useFavoriteOffices } from '@/features/offices/hooks/useFavoriteOffices'; import { useOfficeAvailability } from '@/features/reservations/hooks/useOfficeAvailability'; import theme from '@/theme'; import { MaterialIcons } from '@expo/vector-icons'; export default function OfficeDetailScreen() { const params = useLocalSearchParams<{ officeId: string }>(); const officeId = typeof params.officeId === 'string' ? params.officeId : undefined; const { office, loading, error, reload } = useOffice(officeId); const { favoriteOfficeIdsSet, pendingOfficeId, toggleFavorite, } = useFavoriteOffices(); const { selectedDate, reservations, loading: availabilityLoading, error: availabilityError, setSelectedDate, reload: reloadAvailability, } = useOfficeAvailability(officeId); if (loading) { return ( ); } if (error || !office) { return ( {error ?? "No se pudo cargar el espacio"} Reintentar Volver ); } const isFav = favoriteOfficeIdsSet.has(office.id); const isAvailable = office.available ?? true; return ( {/* cabecera superior */} ← Volver a espacios {/* IMAGE */} {/* TITLE */} {office.name} {office.location ?? "Sin ubicación"} {isAvailable ? "Disponible" : "Ocupado"} {/* CAPACITY */} {office.capacity} personas {/* DESCRIPTION */} {office.description && ( Descripción {office.description} )} {/* AVAILABILITY */} Disponibilidad Consulta los bloques ocupados para elegir un horario libre. Fecha {availabilityLoading ? ( Cargando disponibilidad... ) : null} {availabilityError ? ( {availabilityError} Reintentar ) : null} {!availabilityLoading && !availabilityError ? ( reservations.length > 0 ? ( {reservations.map((reservation) => ( {reservation.startTime} - {reservation.endTime} Ocupado ))} ) : ( No hay bloques ocupados para esta fecha. ) ) : null} {/* FAVORITE */} toggleFavorite(office.id)} disabled={pendingOfficeId === office.id} > {pendingOfficeId === office.id ? "..." : isFav ? "★ Guardado" : "☆ Guardar como favorito"} {/* RESERVE BUTTON */} Reservar ahora ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: theme.colors.background, }, // cabecera superior con el mismo patron que reservas topBar: { backgroundColor: theme.colors.surface, borderBottomWidth: 1, borderBottomColor: theme.colors.border, paddingHorizontal: theme.spacing.xl, paddingTop: theme.spacing.xxxl, paddingBottom: theme.spacing.lg, }, // contenido centrado de la cabecera topBarContent: { maxWidth: theme.layout.contentWidth, width: "100%", alignSelf: "center", }, // texto para volver al listado topBarBack: { color: theme.colors.textSecondary, fontSize: theme.typography.md, }, // scroll principal scroll: { flex: 1, backgroundColor: theme.colors.background, }, // contenido interno del scroll content: { width: "100%", maxWidth: theme.layout.contentWidth, alignSelf: "center", paddingHorizontal: theme.spacing.xl, paddingTop: theme.spacing.lg, paddingBottom: theme.spacing.xxxl, gap: theme.spacing.xl, }, center: { flex: 1, justifyContent: "center", alignItems: "center", padding: theme.spacing.xl, gap: theme.spacing.md, backgroundColor: theme.colors.background, }, imageBox: { width: "100%", height: 180, borderRadius: theme.radius.xl, backgroundColor: theme.colors.primarySoft, alignItems: "center", justifyContent: "center", }, titleRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "flex-start", gap: theme.spacing.md, }, titleBlock: { flex: 1, }, title: { fontSize: theme.typography.xxxl, fontWeight: theme.fontWeight.semibold, color: theme.colors.text, }, subtitle: { color: theme.colors.textSecondary, marginTop: 4, }, metaRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, meta: { color: theme.colors.textSecondary, }, card: { backgroundColor: theme.colors.surface, borderRadius: theme.radius.xxl, padding: theme.spacing.lg, borderWidth: 1, borderColor: theme.colors.border, gap: theme.spacing.md, ...theme.shadows.card, }, sectionTitle: { fontSize: theme.typography.xl, fontWeight: theme.fontWeight.semibold, color: theme.colors.text, }, text: { color: theme.colors.textSecondary, }, availabilityField: { gap: theme.spacing.sm, marginTop: theme.spacing.md, }, label: { color: theme.colors.text, fontWeight: theme.fontWeight.medium, fontSize: theme.typography.sm, }, input: { borderWidth: 1, borderColor: theme.colors.border, borderRadius: theme.radius.md, paddingHorizontal: theme.spacing.lg, paddingVertical: theme.spacing.md, backgroundColor: theme.colors.background, color: theme.colors.text, }, inlineState: { marginTop: theme.spacing.md, flexDirection: "row", alignItems: "center", gap: theme.spacing.sm, }, errorBox: { marginTop: theme.spacing.md, gap: theme.spacing.sm, }, errorText: { color: theme.colors.error, }, retryText: { color: theme.colors.primary, fontWeight: theme.fontWeight.medium, }, occupiedList: { marginTop: theme.spacing.md, gap: theme.spacing.sm, }, occupiedItem: { borderWidth: 1, borderColor: theme.colors.border, borderRadius: theme.radius.md, padding: theme.spacing.md, backgroundColor: theme.colors.background, }, occupiedTime: { color: theme.colors.text, fontWeight: theme.fontWeight.semibold, }, occupiedText: { color: theme.colors.textSecondary, marginTop: theme.spacing.xs, }, availableText: { color: theme.colors.successText, marginTop: theme.spacing.md, }, badge: { backgroundColor: theme.colors.divider, paddingHorizontal: theme.spacing.md, paddingVertical: theme.spacing.xs, borderRadius: theme.radius.sm, }, badgeActive: { backgroundColor: theme.colors.successBg, }, badgeText: { color: theme.colors.textSecondary, fontSize: theme.typography.sm, }, badgeTextActive: { color: theme.colors.successText, }, favoriteButton: { padding: theme.spacing.md, borderRadius: theme.radius.md, backgroundColor: theme.colors.divider, alignItems: "center", }, favoriteButtonActive: { backgroundColor: "#ffe8a3", }, favoriteText: { fontWeight: theme.fontWeight.medium, color: theme.colors.text, }, reserveButton: { backgroundColor: theme.colors.primary, paddingVertical: theme.spacing.lg, borderRadius: theme.radius.lg, alignItems: "center", }, reserveText: { color: theme.colors.white, fontWeight: theme.fontWeight.semibold, fontSize: theme.typography.lg, }, primaryButton: { backgroundColor: theme.colors.primary, padding: theme.spacing.md, borderRadius: theme.radius.md, }, primaryButtonText: { color: theme.colors.white, fontWeight: theme.fontWeight.semibold, }, secondaryButton: { backgroundColor: theme.colors.muted, padding: theme.spacing.md, borderRadius: theme.radius.md, }, });